import React, {Component} from 'react';
import SearchBar from "../../components/SearchBar/SearchBar";
import {Flex, Icon,Toast} from "antd-mobile";
import Filter from "./components/Filter/Filter";
import styles from './index.module.css'
import {require} from "../../netWork";
import HouseItem from "../../components/HoustItem/HouseItem";

class HouseList extends Component {
    state = {
        list: [],
        count: 0
    };

    componentDidMount() {
        this.searchHouseList()
    }

     filters = {};
    //获取筛选数据
    onFilter = (filters) => {

        this.filters = filters;
        console.log(this.filters);
        this.searchHouseList()
    };

    //获取房屋列表数据
    searchHouseList = () => {
        Toast.loading('加载中...', 0, () => {
            console.log('Load complete !!!');
        },true);
        const {value} = localStorage.getItem('hkzf');

        require({
            url: '/houses',
            data: {
                cityId: value,  //当前城市id
                ...this.filters,// 筛选数据
                start: 1,        //分页开始
                end: 200         //分页结束
            }
        }).then(res => {
            // console.log(res);
            this.setState({
                list: res.body.list,
                count: res.body.count
            })
            Toast.hide()
        });

    };


    render() {
        return (
            <div className={styles.root}>
                <Flex className={styles.topbar}>
                    <Icon type="left" size='md' onClick={() => {
                        this.props.history.go(-1)
                    }}/>
                    <SearchBar className={styles.searchHeader}/>
                </Flex>
                    <Filter onFilter={this.onFilter}/>
                <HouseItem houseList={this.state.list}/>
            </div>
        );
    }
}

export default HouseList;
